package com.example.wechattakeaway.service.Impl;

import com.example.wechattakeaway.entity.OrderSupply;
import com.example.wechattakeaway.enums.ResultEnum;
import com.example.wechattakeaway.mapper.OrderSupplyMapper;
import com.example.wechattakeaway.service.OrderSupplyService;
import com.example.wechattakeaway.utils.ResultVOUtil;
import com.example.wechattakeaway.vo.ResultVO;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Repository
public class OrderSupplyServiceImpl implements OrderSupplyService {

    @Autowired
    OrderSupplyMapper orderSupplyMapper;

    @Override
    public ResultVO InsertSupply(Integer orderDetailId, String content) {
        try {
            orderSupplyMapper.InsertSupply(orderDetailId,content);
        }catch (Exception e){
            e.printStackTrace();
            return ResultVOUtil.error(ResultEnum.NORMAL_ERROR);
        }
        return ResultVOUtil.success();
    }

    @Override
    public ResultVO SelectSupplyById(Integer supplyId) {
        OrderSupply orderSupply = new OrderSupply();
        try{
            orderSupply = orderSupplyMapper.SelectSupplyById(supplyId);
        }catch (Exception e){
            e.printStackTrace();
            return ResultVOUtil.error(ResultEnum.NORMAL_ERROR);
        }
        return ResultVOUtil.success(orderSupply);
    }

    @Override
    public ResultVO SelectAllByOrder(Integer pageNum,Integer orderDetailId) {
        PageHelper.startPage(pageNum,5);

        List<OrderSupply> orderSupplyList = new ArrayList<>();
        try{
            orderSupplyList = orderSupplyMapper.SelectAllByOrder(orderDetailId);
        }catch (Exception e){
            e.printStackTrace();
            return ResultVOUtil.error(ResultEnum.NORMAL_ERROR);
        }
        return ResultVOUtil.success(orderSupplyList);
    }
}
